package components.game
{
	import UIFree.effects.other.oef_starsLayer;
	import UIFree.uif_component;
	
	import UIUtils.uif_util;
	
	import classes.clt_events;
	
	import components.clt_component;
	
	import data.cd_stikers;
	import data.cd_utils;
	import data.effects.cd_effects;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class clt_stiker extends clt_component {
		private var _bitmap: Bitmap;
		private var _effect: oef_starsLayer;
		public function clt_stiker(parent:uif_component, ax:int=0, ay:int=0, styleClass:String='stiker', clickEvent: String=clt_events.STIKERCLICK) {
			super(parent, ax, ay, 0, 0, styleClass);
			_bitmap = new Bitmap();
			addChild(_bitmap);
			if (clt.sitedata.STIKERHINT && !clt.user.vipStatus) {
				if (clickEvent) {
					mouseChildren = false;
					buttonMode = true;
					hint = clt.sitedata.STIKERHINT;
					addEvent(MouseEvent.CLICK, function(e: Event): void {
						clt.workspace.dispatchEvent(new Event(clt_events.STIKERCLICK));
						e.stopPropagation();
					});
				}
			}
		}
		
		public function setID(id: int, a_width: int, complete: Function=null): void {
			if (_effect) {
				_effect.dispose();
				_effect = null;
			}			
			clt_stikers.createStikerImage(id, a_width, function(bmd: BitmapData): void {
				if (_bitmap.bitmapData) _bitmap.bitmapData.dispose();
				_bitmap.bitmapData = bmd;
				_bitmap.smoothing = true;
				if (!width || !height) resize(bmd.width, bmd.height);
				else {
					_bitmap.x = (width - bmd.width) / 2;
					_bitmap.y = (height - bmd.height) / 2;
				}
				var edata: Object = cd_utils.fromID(cd_stikers.list, id)
				if (edata.stars) {
					_effect = new oef_starsLayer(This, bmd.rect, uif_util.union(edata.stars, {mask: bmd}));
					_effect.x = _bitmap.x;
					_effect.y = _bitmap.y;
				} 
				if (complete != null) complete();
			});
		}
	}
}